import os
import random
import logging

logger = logging.getLogger(__package__)


class UserAgent:
    def __init__(self):
        basepath = os.path.abspath(__file__)
        folder = os.path.dirname(basepath)
        data_path = os.path.join(folder, "user_agent")
        f = open(data_path)
        text = f.read()
        self.user_agent = text.splitlines()

    def get(self):
        try:

            return self.user_agent[random.randint(0, len(self.user_agent) - 1)]
        except BaseException as val:
            logger.warning('Errors:', val.args)
